package com.hospital.auth.controller;

import com.hospital.auth.feign.SystemService;
import com.hospital.auth.service.DoctorLoginService;
import com.hospital.common.domain.response.JwtResponse;
import com.hospital.common.domain.system.Doctor;
import com.hospital.common.exceptions.ServiceException;
import com.hospital.common.result.R;
import com.hospital.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：zhuzhujiang
 * @Description:
 * @name：DoctorLoginController
 * @Date：2024/10/19 12:02
 */
@RestController
@RequestMapping("/doctorLogin")
public class DoctorAdminLoginController {

    @Autowired
    private DoctorLoginService doctorLoginService;
    @Autowired
    private SystemService systemService;

    /**
     * 医生和管理员登录
     * @param doctor
     * @return
     */
    @PostMapping("login")
    public R login(@RequestBody Doctor doctor) {

        //判断账号密码是否为空
        if(StringUtils.isAllBlank(doctor.getAccount(), doctor.getPassword())){
            throw new ServiceException("账号或密码为空！",401);
        }
        JwtResponse jwtResponse = doctorLoginService.login(doctor);
        return R.success(jwtResponse);

    }

    /**
     * 获取医生登录信息
     */
    @GetMapping("/info")
    public R<Doctor> getInfo(){


        return R.success(doctorLoginService.getInfo());

    }


    /**
     * 登出
     */
    @GetMapping("/logout")
    public R logout(){
        doctorLoginService.logout();

        return R.success("退出成功");

    }

    /**
     * 医生进行注册
     */
    @PostMapping("/registy")
    public R register(@RequestBody Doctor doctor){

        systemService.doctorRegister(doctor);

        return R.success("注册成功");

    }





}
